import pytest
import requests
import conftest


class Test_login():

    def setup_method(self):
        #定义登录接口URL地址
        self.login_url = "http://192.168.3.182:9990/airservice-sso/sso/login"


    #case01  登录成功
    #@pytest.mark.skip(reason="跳过")
    def test_login_success(self):
        self.login_data ={"account": "wsf",
                     "password": "645b544257b819ad1fff479e7435034f",  #wsf1234
                     "loginType": 1,
                     "isRemember": 1 }

        response = requests.post(url=self.login_url, json=self.login_data)

        #print(response.json())

        #添加断言
        assert response.json().get("message") == "操作成功"
        assert  response.json().get("success") == True

        # 提取token信息 保存在配置文件conftest.py中-----相当于全局变量
        conftest.TOKEN=response.cookies.get("x-auth-token")
        print(conftest.TOKEN)

        # 将获取到的token 追加写到conftest.py中定义的字典headers_data中，{"x-auth-token"：conftest.TOKEN}
        conftest.headers_data["x-auth-token"] = conftest.TOKEN
        # print(conftest.headers_data["x-auth-token"])
        print(conftest.headers_data)

